//
//  NYMyExamineDetailViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/8.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyExamineDetailViewController.h"
#import "NYMyExamineDetailRequest.h"
#import "NYMyExamineDetailHeaderCell.h"
@interface NYMyExamineDetailViewController ()
@property(nonatomic, strong) NYMyExamineDetailRequest *request;
@end

@implementation NYMyExamineDetailViewController


- (void)viewDidLoad
{
        [super viewDidLoad];
        if (self.detailModel) {
                [self configNimbusData];
        } else {
                [self loadData];
        }
}
- (void)configNimbusData
{
        [self configNimbus];
//        if (self.detailModel.score_statistics!= nil && self.detailModel.score_statistics.count > 0) {
                [self.tableViewModel addObject:[NICellObject objectWithCellClass:[NYMyExamineDetailHeaderCell class] userInfo:self.detailModel]];
//        }
        if (self.detailModel.results.count > 0) {
                [self.tableViewModel addObjectsFromArray:self.detailModel.results];
        }
        [self.tableView reloadData];
}
- (void)configNimbus
{
        [super configNimbus];
        [self.tableViewActions attachToClass:[NYMyExamineResultModel class] tapBlock:^BOOL(NYMyExamineResultModel * object, NYMyExamineDetailViewController * target, NSIndexPath *indexPath) {
                
                [target routeUrl:kNYSubjectAnalysisURI param:@{
                                                             kRequestKeyType : @(target.analysisType),
                                                             kRequestKeyTypeID : NOT_NULL_STRING_DEFAULT_EMPTY(object.analysis)
                                                             }];
                
                return YES;
        }];
}
- (void)loadData
{
        [self setLoading:YES animation:YES];
        self.request = [NYMyExamineDetailRequest requestWithParams:@{
                                                                     kRequestKeyTypeID : @(self.classType),
                                                                     kRequestKeyExamineID : NOT_NULL_STRING_DEFAULT_EMPTY(self.examineID),
                                                                     }];
        [self.request startWithSuccess:^(__kindof BaseRequest * _Nonnull request, __kindof NYMyExamineDetailModel * _Nonnull data) {
                self.detailModel = data;
                [self configNimbusData];
                [self setSuccess];
        } failed:^(__kindof BaseRequest * _Nonnull request, NSError * _Nonnull error) {
                [self setError:error];
        }];
}

- (void)configNavigationBar:(BaseNavigationBar *)navigationBar
{
        [super configNavigationBar:navigationBar];
        self.title = @"考试结果";
}

+ (NYViewControllerNavigationBarType)navigationBarType
{
        return NYViewControllerNavigationBarTypeBlue;
}

@end
